﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Commonlib;
using Albon.Model;
namespace DAL
{
    public class ItemClothDAL
    {

        //选择布料
        public bool selectCloth(ItemCloth itemcloth)
        {
            SqlParameter[] parameters = new SqlParameter[] { 
                new SqlParameter("@id",itemcloth.ID),
                new SqlParameter("@companyName",itemcloth.companyName),
                new SqlParameter("@clothNo",itemcloth.clothNo),
                new SqlParameter("@widthKind",itemcloth.widthKind),
                new SqlParameter("@clothSize",itemcloth.clothSize),
                new SqlParameter("@clothPrice",itemcloth.clothPrice)
            };
            int ret=SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnectionString, CommandType.StoredProcedure, "p_itemclothselect", parameters);
            return ret==1;
        }
        /// <summary>
        /// 完成尺寸信息后添加主布料
        /// </summary>
        public bool addItemCloth(ItemCloth itemcloth)
        {
            SqlParameter[] parameters = new SqlParameter[] { 
                new SqlParameter("@orderItemId",itemcloth.orderItemID),
                new SqlParameter("@styleID",itemcloth.styleID),
                new SqlParameter("@styleName",itemcloth.Stylename),
                new SqlParameter("@clothSize",itemcloth.clothSize)
            };
            int ret=SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnectionString, CommandType.StoredProcedure, "p_itemclothadd", parameters);
            return ret > 0;
        }
        /// <summary>
        /// 根据传入的选择条件查询数据
        /// </summary>
        public DataTable getItemCloth(string limit)
        {
            string cmdstr="select * from ItemClothView where active=1 and "+limit;
            return SqlHelper.ExecuteDataSet(SqlHelper.SqlConnectionString, CommandType.Text, cmdstr, null).Tables[0];
        }

        /// <summary>
        /// 更新布料信息中的尺寸
        /// </summary>
        public bool updateItemSize(ItemCloth itemcloth)
        {
            SqlParameter[] parameters = new SqlParameter[] { 
                new SqlParameter("@orderitemid",itemcloth.orderItemID),
                new SqlParameter("@styleName",itemcloth.Stylename),
                new SqlParameter("@clothsize",itemcloth.clothSize)
            };
            int ret = SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnectionString, CommandType.StoredProcedure, "p_itemclothupd", parameters);
            return ret > 0;
        }
        /// <summary>
        /// Clear Option Cloth
        /// </summary>
        public void clearCloth(string orderitemid)
        {
            string cmdstr = "update ItemCloth set active=0 where orderItemID=" + orderitemid + " and styleID!=0";
            SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnectionString, CommandType.Text, cmdstr, null);
        }

        /// <summary>
        /// 更新布料状态
        /// </summary>
        /// <param name="itemcloth"></param>
        public void buyCloth(string idlist,ItemCloth itemcloth)
        {
            SqlParameter[] parameters = new SqlParameter[] {
                new SqlParameter("@idlist",idlist),
                new SqlParameter("@statusID",itemcloth.statusID),
                new SqlParameter("@purchaser",itemcloth.purchaser),
                new SqlParameter("@buyRemark",itemcloth.buyRemark)
            };
            SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnectionString, CommandType.StoredProcedure, "p_itemclothbuy", parameters);
        }

        //更新布料状态（备注中显示修改日志）
        public void updateStatus(string idlist,string statusID, string statusRemark)
        {
            SqlParameter[] parameters = new SqlParameter[] {
                new SqlParameter("@idlist",idlist),
                new SqlParameter("@statusID",statusID),
                new SqlParameter("@statusRemark",statusRemark)
            };
            SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnectionString, CommandType.StoredProcedure, "p_itemclothupstatus", parameters);
        }
    }
}
